import { z } from "zod";
import path from "path";
import { fileURLToPath } from "url";
import { getSystematicReadContentPrompt } from "../../prompts/index.js";
import { getMemoryDir } from "../../utils/paths.js";

// 系统性读取相关内容工具
// Systematic Read Content Tool
export const systematicReadContentSchema = z.object({
  targetTopic: z
    .string()
    .min(5, {
      message: "目标主题不能少于5个字符，请提供更具体的主题描述",
    })
    .describe("需要收集信息的目标主题或问题领域"),
  informationSources: z
    .array(z.enum(['project_internal', 'technical_docs', 'community_resources', 'official_docs', 'code_repository', 'issue_tracker']))
    .optional()
    .default(['project_internal', 'technical_docs'])
    .describe("信息来源类型列表"),
  priorityLevel: z
    .enum(['high', 'medium', 'low'])
    .optional()
    .default('medium')
    .describe("信息收集的优先级级别"),
  qualityRequirement: z
    .enum(['basic', 'standard', 'comprehensive'])
    .optional()
    .default('standard')
    .describe("信息质量要求级别")
});

export async function systematicReadContent({
  targetTopic,
  informationSources = ['project_internal', 'technical_docs'],
  priorityLevel = 'medium',
  qualityRequirement = 'standard'
}: z.infer<typeof systematicReadContentSchema>) {
  // 获取基础目录路径
  // Get base directory path
  const __filename = fileURLToPath(import.meta.url);
  const __dirname = path.dirname(__filename);
  const PROJECT_ROOT = path.resolve(__dirname, "../../..");
  const MEMORY_DIR = await getMemoryDir();

  // 使用prompt生成器获取最终prompt
  // Use prompt generator to get the final prompt
  const prompt = await getSystematicReadContentPrompt({
    targetTopic,
    informationSources,
    priorityLevel,
    qualityRequirement,
    memoryDir: MEMORY_DIR,
  });

  return {
    content: [
      {
        type: "text" as const,
        text: prompt,
      },
    ],
  };
}
